const app = getApp()
const publicFun = require('/utils/public.js')
import { getClimateActionTJ, getClimateActionType, getClimateActionWithoutType } from '/utils/request'
Page({
  data: {
    zhouqitype: 0
  },
  onLoad(options) {
    this.setData({
      myClimeteList: [],
      systemInfo: app.globalData.systemInfo,
      userid: options.userid ? options.userid : app.globalData.userid,
      zhouqitype: options.zhouqitype
    });
  },
  onShow() {
    this.getTJList();
    this.getTPList();
  },
  WaterfallFlowTap(e) {
    let data = e.currentTarget.dataset;
    my.navigateTo({
      url: '/pages/userCardDetail/userCardDetail?userid='+this.data.userid+'&typeid='+data.typeid+"&zhouqitype="+this.data.zhouqitype
    })
  },
  async getTJList() { 
    try{
      var params = {
        userid: this.data.userid,
        zhouqitype: this.data.zhouqitype,
        isfrombangdang: 1
      }
      const res = await getClimateActionTJ(params)
      if(res.S == 1){
        let data = res;
        this.setData({ myClimateData: data })
      }else{
        publicFun.showToast(res.M ? res.M : '加载失败')
      }
    }catch(e){
      publicFun.showToast('失败，请稍后再试')
    }
  },
  async getTPList() { 
    try{
      var params = {
        actiontypeid: app.globalData.actiontypeid,
        userid: this.data.userid,
        zhouqitype: this.data.zhouqitype,
        isfrombangdang: 1
      }
      if(this.data.zhouqitype == 0){
        var res = await getClimateActionType(params)
      }else{
        var res = await getClimateActionWithoutType(params)
      }
      if(res.S == 1){
        let list = res.L;
        this.setData({ myClimeteList: list})
      }else{
        publicFun.showToast(res.M ? res.M : '加载失败')
      }
    }catch(e){
      publicFun.showToast('失败，请稍后再试')
    }
  },
});
